#http://www.cam4.com/direct?username=wearehere4yo&room=wearehere4yo
#rtmp://199.59.88.26/cam4-chat94
#http://199.59.88.26:1935/room,wearehere4yo
#rtmp://199.59.88.18/cam4-origin77/_definst_/streams/daf35721-bf68-4863-9f41-d5c878935067





echo "Please enter performer name:"
read name
echo "Welcome to Edinburgh $name"
url="http://www.cam4.com/direct?username="$name"&room="$name
#xdg-open $url

content=$(wget "http://www.cam4.com/direct?username="$name"&room="$name -q -O -)
echo "url-ul generat este:"$content

conv1=$(printf $content | sed "s/rtmp:\/\///")
echo $conv1
conv2=$(printf $conv1 | sed "s/\/[A-Za-z0-9].*//")
echo $conv2
newContentURL="http://"$conv2":1935/room,"$name
echo "opening "$newContentURL
newContent=$(wget $newContentURL -q -O -)
echo "url-ul generat este: "$newContent

filename=$(printf $newContent | sed -e "s/\(.*\)\///g" )
urlname=$(printf $newContent | sed "s/$filename//")

echo "nume fisier este: "$filename
echo "nume url server este: "$urlname
#rtmpdump -r $newContent -o test.flv
#exit
echo "select type: R FF1"


read getType


rtm="R"
rtmP="FF1"

case $getType in

$rtm)
echo "rulam cu rtmpdump"
rtmpdump -r $newContent -o test.flv;;

$rtmP)
echo "rulam cu ffmpeg basic format, type folder name withoout commas:"
read folderName
echo "salvam in "$folderName
ffmpeg -i $newContent -an -r 1 -s 320x240 -y $folderName/video%d.jpg;;

"undef")
echo "e egal cu sec";;

*)
echo "default";;

esac

exit
